#include <Arduino.h>

const int stepPin = 4;
const int dirPin = 3;
int customDelay,customDelayMapped;

// put function declarations here:
int speedUp();

void setup() {
  // put your setup code here, to run once:
  pinMode(stepPin,OUTPUT);
  pinMode(dirPin,OUTPUT);

  digitalWrite(dirPin,HIGH);
}

void loop() {
  // put your main code here, to run repeatedly:
  customDelayMapped=speedUp();
  digitalWrite(stepPin,HIGH);
  delayMicroseconds(customDelayMapped);
  digitalWrite(stepPin,LOW);
  delayMicroseconds(customDelayMapped);
}

// put function definitions here:
int speedUp() {
  int cusDelay = analogRead(A0);
  int newDelay = map(cusDelay,0,1023,300,4000);
  return newDelay;
}